from time import sleep
import requests

def main1():
    
    return float(requests.get("https://api.jdjygold.com/gw/generic/hj/h5/m/latestPrice").json()['resultData']['datas']['price'])
    v2= v*a
    p= '%s - 499.97046 = %s' %(v2, (v2-499.97046))
    print(p, end='\r')

def main2(a):

    return main1()- a

def main3(a, a2_g):

    return main2(a)* a2_g
    try:
        v= main()
        while v> 365:
                v3= main()-500
                v3= 0
    except:
        pass

    sleep(5)

def main4(a_message=''):

    print("\nSending email")
    from email.mime.text import MIMEText
    from smtplib import SMTP_SSL

    smtp_serv = 'smtp.qq.com'
    smtp_port = 465
    smtp_addr = '2907821379@qq.com'
    email_receiver = '2907821379@qq.com'
    smtp_name = '2907821379'
    smtp_pass = ''
    email_title=a_message
    email_content='请注意金价'
    msg = MIMEText(email_content, 'plain', 'utf-8')
    msg["Subject"]=email_title
    msg["From"]=smtp_addr
    msg["To"]=email_receiver
    smtp = SMTP_SSL(smtp_serv, smtp_port)
    smtp.set_debuglevel(0)
    smtp.ehlo(smtp_serv)
    smtp.login(smtp_name,smtp_pass)
    smtp.sendmail(smtp_addr, email_receiver, msg.as_string())
    sleep(600)

v= float(main2(365))

while True:
    while v>0:
        try:
            v= float(main2(365))
            print('返回值 - 预期值 = %s' %v, end='\r')
        except:
            print('获取失败', end='\r')
        sleep(4)

    main4()

